"use client";
import { useRouter, useSearchParams } from "next/navigation";
import OneMoreStep from "./oneMoreStep";
import NormalForm from "./normalForm";
import { login } from "@/service/common";

const SignIn = () => {
  const router = useRouter();
  const searchParams = useSearchParams();
  const step = searchParams.get("step");

  const initUser = async () => {
    const loginData: Record<string, any> = {
      email: "wangfengbj@163.com",
      password: "Zzsn@2024zzsN",
      language: "zh-Hans",
      remember_me: true,
    };

    const res = await login({
      url: "/login",
      body: loginData,
    });
    if (res.result === "success") {
      localStorage.setItem("console_token", res.data.access_token);
      localStorage.setItem("refresh_token", res.data.refresh_token);
      router.replace("/apps");
    }
  };
  initUser();

  if (step === "next") return <OneMoreStep />;
  return <NormalForm />;
};

export default SignIn;
